package com.wmlive.hhvideo.heihei.login.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.base.BasePresenter;
import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.login.view.SmsView;
import com.wmlive.hhvideo.heihei.beans.login.SmsResponse;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.networklib.entity.DCNetObserver;

/**
 * Created by vhawk on 2017/5/23.
 */

public class SmsPresenter extends BasePresenter<SmsView> {

    public SmsPresenter(SmsView view) {
        super(view);
    }

    /**
     * 发送验证码
     *
     * @param mobile
     */
    public void sendSmsCode(String mobile) {

        String url = InitCatchData.userGetSMSVerificationCode();

        if (!TextUtils.isEmpty(url)) {
            executeRequest(HttpConstant.TYPE_SMS_CODE, getHttpApi().sendSmsCode(url, mobile))
                    .subscribe(new DCNetObserver<SmsResponse>() {
                        @Override
                        public void onRequestDataReady(int requestCode, String message, SmsResponse response) {
                            if (null != viewCallback) {
                                viewCallback.handleSmsSucceed();
                            }
                        }

                        @Override
                        public void onRequestDataError(int requestCode, int serverCode, String message) {
                            if (null != viewCallback) {
                                viewCallback.handleSmsFailure(message);
                            }
                        }
                    });

        } else {
            if (null != viewCallback) {
                viewCallback.handleNetError();
            }
        }


    }


}
